/**
  * @file		arduino.c
  * @author		Naresuan University: Advance Computer System, class of 2013
  * @version	V1.0.0
  * @date		18-September-2013
  * @brief		Arduino module
  */

/* Includes ------------------------------------------------------------------*/

#include "arduino.h"

/* Private typedef -----------------------------------------------------------*/
/* Private define ------------------------------------------------------------*/
/* Private macro -------------------------------------------------------------*/
/* Private variables ---------------------------------------------------------*/
static uint32_t Millis = 0;

/* Private function prototypes -----------------------------------------------*/
/* Private functions ---------------------------------------------------------*/


/**
  * @brief		IRQ for 1-ms tick.
  * @param		None
  * @retval		None
  */
	
void SysTick_Handler()
{
	Millis++;
}

  
/**
  * @brief		Configure hardware for Arduino compatibility
  * @param		None
  * @retval		None
  */
void Platform_config(void)
{
	SysTick_Config(SystemCoreClock/1000);
}


/**
  * @brief		Pauses the program for the amount of time (in miliseconds) specified as parameter.
  * @param		ms			Number of milliseconds to pause. 
  * @retval		None
  */
void delay(uint32_t ms)
{
	uint32_t start = Millis;
	while ((Millis - start) < ms);
}

